Watch as we step through the algorithm: dequeue a node, process it, and enqueue its unvisited neighbors.
- The process begins by dequeuing the start node 'A'. Its status changes from "discovered" to "processed".
- 'A's neighbors, 'B' and 'C', are unvisited, so they are marked "discovered" and enqueued.
- Next, 'B' is dequeued and processed. Its unvisited neighbors, 'D' and 'F', are discovered and enqueued.
- 'C' is then dequeued and processed, leading to 'E' being discovered and enqueued.
- The remaining nodes are dequeued, but since all their neighbors have already been discovered, no new nodes are added to the queue.
- The key takeaway is observing how the queue manages the frontier of discovered nodes, ensuring a level-by-level exploration.
| Step | Dequeue | Enqueue | Queue After |
|---|---|---|---|
| 1 | A | B, C | [B, C] |
| 2 | B | D, F | [C, D, F] |
| 3 | C | E | [D, F, E] |
| 4 | D | [F, E] | |
| 5 | F | [E] | |
| 6 | E | [] |